<?php
class Kanedo_Cookie
{
	protected $_cache = array();
	public function __construct()
	{
	}
	
	public function set($key, $val, $expire = 30)
	{
		if ($expire) setcookie($key, $val, time()+60*60*24*$expire, "/");
	}
	
	public function __get($key)
	{
		if (isset($_COOKIE[$key]))
		{
			return $_COOKIE[$key];
		}else {
			return false;
		}
	}
	public function __sleep()
	{
		foreach ($_COOKIE as $key => $val)
		{
			$this->_cache[$key] = $val;
		}
		return array("_cache");
	}
	
	public function __wakeup()
	{
		foreach($this->_cache as $key => $val)
		{
			if (!isset($_COOKIE[$key]))
			{
				$this->__set($key, $val);
			}
		}
	}
	public function deleteCookie($name)
	{
		 $tStamp = time() - 432000;
         setcookie($name,"",$tStamp, "/");
	}
}
?>